   var qs = (location.search.length > 0 ? location.search.substring(1) : "")
    var search = decodeURIComponent(qs.substring(qs.indexOf("=")+1, qs.length));
    $("#search_input").val(search);
    
    if(search == "" || search == null){
    	console.log(search+"1111");
    }else{
    	console.log(search+"222");
    	$("#find_classes").empty();
      $.ajax({
        type:"get",
        url :"http://192.168.30.174:8088/solr/SolrSearch?name="+search,
        dataType : "json",
        success:function(data){
           
           function addSeachbox(data){

               //手动
               if(data.length > 0){
                   $("#find-classnum").text(data.length);
                   $(".find_error").hide();
                   $("#find_msg").show();
               }else{
                   $("#find_msg").hide();
               }

               $(".find_classes").height("auto");

               $.each(data, function(index, value){
                   var $append = "<a href='ResHome.jsp?courseId="+value.courseId+"'>"+
                                     "<div class='find_each'>"+
                                         "<img src='"+value.courseImg+"'>" +
                                         "<div class='class_msg'>" +
                                             "<div class='class_name'>"+value.courseName+"</div>"+
                                             "<div class='class_learns'>"+
                                         "</div>"+
                                         "<div class='class_author'>"+
                                             "<span>讲师：</span>"+
                                             "<span>"+value.courseAuthor+"</span>"+
                                         "</div>"+
                                         "<div class='class_info'>"+
                                             "<span>"+value.courseDesc+"</span>"+
                                         "</div>"+
                                     "</div>"+
                                "</a>";

                   $("#find_classes").append($append);
               });

           }

           if(data.length < 1){
          	 $("#find_classes").append(showNone);
           }else{
               addSeachbox(data);
           }
   
        },
        error:function(){
            console.log("请求数据出错");
        }

   })
    }
    
    //这里再发送ajax请求，首次加载页面（如果从首页过来的搜索）
    
    var showNone = "<div class='find_error'><img src='images/search/unfind.png'><div>啊哦~我们没有找到您想要搜索的内容</div></div>";
    
    //如果不是从首页过来的搜索，直接点击搜索
    $("#search_msg").click(function(){
       var searchmsg = $("#search_input").val();
        //alert(searchmsg);
        if(searchmsg == null || searchmsg == ""){
            //如果不为空才发送ajax请求
        	alert("请输入搜索内容")
        }else{
        	$("#find_classes").empty();
        	  console.log(searchmsg)
            $.ajax({
              type:"get",
              url :"http://192.168.30.174:8088/solr/SolrSearch?name="+searchmsg,
              dataType : "json",
              success:function(data){
                 
                 function addSeachbox(data){

                     //手动
                     if(data.length > 0){
                         $("#find-classnum").text(data.length);
                         $(".find_error").hide();
                         $("#find_msg").show();
                     }else{
                         $("#find_msg").hide();
                     }

                     $(".find_classes").height("auto");

                     $.each(data, function(index, value){
                         var $append = "<a href='ResHome.jsp?courseId="+value.courseId+"'>"+
                                           "<div class='find_each'>"+
                                               "<img src='"+value.courseImg+"'>" +
                                               "<div class='class_msg'>" +
                                                   "<div class='class_name'>"+value.courseName+"</div>"+
                                                   "<div class='class_learns'>"+
                                               "</div>"+
                                               "<div class='class_author'>"+
                                                   "<span>讲师：</span>"+
                                                   "<span>"+value.courseAuthor+"</span>"+
                                               "</div>"+
                                               "<div class='class_info'>"+
                                                   "<span>"+value.courseDesc+"</span>"+
                                               "</div>"+
                                           "</div>"+
                                      "</a>";

                         $("#find_classes").append($append);
                     });

                 }

                 if(data.length < 1){
                	 $("#find_classes").append(showNone);
                 }else{
                     addSeachbox(data);
                 }
         
              },
              error:function(){
                  console.log("请求数据出错");
              }

         })
        }
    });
    
    
   
    

  